package com.video.exception;

import com.video.result.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(VideoException.class)
    public ResultVO systemExceptionHandler(VideoException e) {
        //打印异常信息
        log.error("出现了异常！ {}", e);
        //从异常对象中获取提示信息封装返回
        return ResultVO.error(e.getCode(), e.getMsg());
    }
    
    @ExceptionHandler(SystemException.class)
    public ResultVO exceptionHandler(SystemException ex) {
        return ResultVO.error(ex.getCode(), ex.getMessage());
    }

}
